export function ref(object) {
    return new Proxy(object, {
        get(target, prop) {
            if (prop == 'value' && target._isRef) {
                return target._value
            }
            let value, paths
            if (target._isRef) {
                if (target._hasValue) {
                    value = target._value[prop]
                } else {
                    // console.log(target, '不存在此配置')
                }
                paths = [...target._paths, target]
            } else {
                value = target[prop]
                paths = [target]
            }
            return ref({
                _key: prop,
                _value: value,
                _hasValue: !!value,
                _isRef: true,
                _paths: paths
            })
        },
        set(target, prop, value) {
            if (target._isRef) {
                if (!target._hasValue) {
                    console.log(target, '创建此配置')
                }
                if (prop == 'value') {
                    target._value = value
                } else {
                    target._value[prop] = value
                }
            }
            return true
        },
        deleteProperty(target, prop) {
            // 拦截数组元素的删除
            console.log(`Deleting element at index: ${prop}`)
            delete target[prop]
            return true // 表示删除成功
        }
    })
}
